package utils;

public class MobileUtil {

    //过滤空格特殊符号
    public static String filterPhone(String phone){
        return phone.replaceAll("[^0-9]", "");
    }

    /**
     * 过滤手机号的中国区号0086
     */
    public static String filterPrefix86(String phone){
        return phone.replaceAll("^[\\+,0]*86", "");
    }

    public static String formatPhone(String phone){
        if (StringUtils.isNullOrEmpty(phone)
                || phone.length() < 7
                || phone.contains("*")
                || phone.contains(".")
                || phone.startsWith("400")
                || phone.startsWith("800")) return null;
        phone = filterPhone(phone);
        phone = filterPrefix86(phone);
        return phone.isEmpty() ? null : phone;
    }
}
